<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
    <th:block th:include="include :: header('新增需求跟踪')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-detailetrack-add">
            <input name="relateId"  type="hidden"  id="treeId" />
            <!--            <div class="form-group">-->
<!--                <label class="col-sm-3 control-label">分组文件夹父ID：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="parentId" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">业务类型：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="programName" onclick="selectCdTree()" id="treeName" type="text" placeholder="请选择项目" class="form-control">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('cd_tracktype')}">
                        <input type="radio" th:id="${'typeId_' + dict.dictCode}" name="typeId" th:value="${dict.dictValue}" th:checked="${dict.dictCode == 46 ? true : false}">
                        <label th:for="${'typeId_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">需求内容：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="content">
                    <div class="summernote" id="content"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">晋云对接人：</label>
                <div class="col-sm-8">
                    <input name="jinyunPeople" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('cd_status')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.dictCode == 30 ? true : false}" required>
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">当前进度：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="bakContent">
                    <div class="summernote" id="bakContent"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">负责人：</label>
                <div class="col-sm-8">
                    <input name="responsPeople" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">计划完成时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="completeTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
			<div class="form-group">
                <label class="font-noraml">附件上传</label>
                <div class="file-loading">
                    <input id="multipleFile" name="files" type="file" multiple>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "cd/detailetrack"
        var rspUrls = ""//附件url
        var rspNewFileNames = ""//附件名称
        $("#form-detailetrack-add").validate({
            focusCleanup: true
        });
        /* 选择项目树 */
        function selectCdTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "6" : $("#treeId").val();//6晋云集团
            var url = ctx + "cd/program/selectProgramTree/" + deptId;
            var options = {
                title: '选择项目',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
        function submitHandler() {
			if($('#multipleFile')[0].files[0]!=undefined){
                $.modal.msgError("含有未上传的文件，请先上传文件后再提交")
                return
            }
            var msg = $('#form-detailetrack-add').serialize()
            msg = msg + '&ext3='+rspNewFileNames+'&ext4='+rspUrls;
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", msg);
            }
        }

        $("input[name='completeTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                dialogsInBody: true,
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });

        $(document).ready(function () {
            // 多文件上传
            $("#multipleFile").fileinput({
                uploadUrl: ctx + 'common/uploads',
                uploadAsync: false
            }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
                var rsp = data.response;
                log.info("return urls：" + rsp.urls)//http://localhost:8089/profile/upload/2024/04/29/SSS.png,http://localhost:8089/profile/upload/2024/04/29/viewImage_20240429175810A004.png
                log.info("reutrn fileNames：" + rsp.fileNames)
                log.info("reutrn newFileNames：" + rsp.newFileNames)//SSS.png,viewImage_20240429175810A004.png
                log.info("return originalFilenames：" + rsp.originalFilenames)
                rspUrls = rsp.urls
                rspNewFileNames = rsp.originalFilenames
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
        });
    </script>
</body>
</html>
